<extend name="Base/common"/>
<block name="style">
    <link href="__CSS__/issue.css" rel="stylesheet" type="text/css"/>
</block>
<block name="body">
    <div id="frm-post-popup" class="white-popup boxShadowBorder" style="max-width: 745px">
        <h2>编辑</h2>

        <div class="aline" style="margin-bottom: 10px"></div>
        <div>
            <div class="row">
                <div class="col-md-4">
                    <div class="controls">
                        <input type="file" id="upload_picture_cover">

                        <div class="upload-img-box" style="margin-top: 20px;width: 250px">
                            <div class="upload-pre-item"><img src="{$content.cover_id|get_cover='path'}"></div>
                        </div>
                    </div>

                </div>
                <div class="col-md-8">
                    <form class="form-horizontal  ajax-form" role="form" action="{:U('Issue/Index/doPost')}"
                          method="post">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">标题</label>

                            <div class="col-sm-10">
                                <input id="title" name="title" class="form-control" value="{$content.title}" placeholder="标题"/>
                            </div>
                            <input type="hidden" name="id" id="id" value="{$content.id}"/>
                            <input type="hidden" name="cover_id" id="cover_id_cover" value="{$content.cover_id}"/>
                        </div>
                        <div class="form-group">
                            <label for="issue" class="col-sm-2 control-label">分类</label>

                            <div class="col-sm-5">
                                <select id="issue_top" name="issue" class="form-control">
                                    <volist name="tree" id="top">
                                        <option value="{$top.id}" <eq name="top_issue" value="$top['id']"> selected</eq>>
                                            {$top.title}
                                        </option>
                                    </volist>
                                </select>
                            </div>

                            <script>
                                    var first_load=true;

                                        $('#issue_top').change(function(){
                                            var pid=$(this).val();
                                            $.post("{:U('Issue/Index/selectDropdown')}",{pid:pid},function(data){
                                                $('#issue_second').html('');
                                                $.each(data,function(index,element){

                                                            $('#issue_second').append('<option value="'+element.id+'">'+element.title+'</option>')
                                                        }
                                                );

                                                if(first_load){
                                                $('#issue_second').val("{$content.issue_id}");
                                            first_load=false;

                                        }
                                    },'json');
                                });
                                $('#issue_top').change();



                            </script>
                            <div class="col-sm-5">
                                <select id="issue_second" name="issue_id" class="form-control">
                                  <option>请选择一级分类</option>
                                </select>
                            </div>

                        </div>
                        <div class="form-group">
                            <label for="url" class="col-sm-2 control-label">网址</label>

                            <div class="col-sm-10">

                                <input id="url" name="url" type="text" class="form-control" value="{$content.url}" placeholder="输入以http://开头的网址"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">介绍</label>

                            <div class="col-sm-10">

                                <php>
                                    $config="toolbars:[['source','|','bold','italic','underline','fontsize','forecolor','justifyleft','fontfamily','|','map','emotion','insertimage','insertcode']]";
                                </php>

                                {:W('Common/Ueditor/editor',array('myeditor_edit','content',$content['content'],'378px','250px',$config))}
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-2">
                                <button type="submit" class="btn btn-primary " href="{:U('Issue/Index/doPost')}">提交
                                </button>

                            </div>
                            <div class="col-sm-8">
                                <button onclick="history.go(-1);" class="btn btn-primary " href="{:U('Issue/Index/doPost')}">返回
                                </button>
                            </div>

                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <script>
        $("#upload_picture_cover").uploadify({
            "height": 30,
            "swf": "__STATIC__/uploadify/uploadify.swf",
            "fileObjName": "download",
            "buttonText": "上传封面",
            "buttonClass": "uploadcover",
            "uploader": "{:U('Core/File/uploadPicture',array('session_id'=>session_id()))}",
            "width": 250,
            'removeTimeout': 1,
            'fileTypeExts': '*.jpg; *.png; *.gif;',
            "onUploadSuccess": uploadPicturecover,
            'overrideEvents': ['onUploadProgress', 'onUploadComplete', 'onUploadStart', 'onSelect'],
            'onFallback': function () {
                alert('未检测到兼容版本的Flash.');
            }, 'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
                $("#cover_id_cover").parent().find('.upload-img-box').html(totalBytesUploaded + ' bytes uploaded of ' + totalBytesTotal + ' bytes.');
            }, 'onUploadComplete': function (file) {
                //alert('The file ' + file.name + ' finished processing.');
            }, 'onUploadStart': function (file) {
                //alert('Starting to upload ' + file.name);
            }, 'onQueueComplete': function (queueData) {
                // alert(queueData.uploadsSuccessful + ' files were successfully uploaded.');
            }
        });
        function uploadPicturecover(file, data) {
            var data = $.parseJSON(data);
            var src = '';
            if (data.status) {
                $("#cover_id_cover").val(data.id);
                src = data.url || data.path
                $('.upload-img-box').html(
                        '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                );
            } else {
                toast.error('封面上传失败。', '温馨提示');
            }
        }
    </script>
</block>